# @Time:   2020/12/8 11:02
# @Author: Zong Wei

"""
Project Public Configuration
"""
import configparser
import os

# PATH INFO
BASE_PATH = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
DATA_PATH = os.path.join(BASE_PATH, "data")
DRIVER_PATH = os.path.join(BASE_PATH, "drivers")
LOG_PATH = os.path.join(BASE_PATH, "logs")
REPORT_PATH = os.path.join(BASE_PATH, "report")
CASES_PATH = os.path.join(BASE_PATH, "test", "test_cases")

# URL INFO
# TEST_URL = "http://test.mcpsystem.com/"
TEST_URL = "http://10.130.134.90/"  # 新测试地址
LIVE_URL = "http://www.mcpsystem.com/"


class MyConfig:
    @staticmethod
    def get_config_file(file_name):
        base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
        config_path = os.path.join(base_path, "config")
        file_path = os.path.join(config_path, file_name)
        try:
            config = configparser.ConfigParser()
            config.read(file_path)
            return config
        except Exception as e:
            print('read config file error:' + str(e))

    def get_value(self, file_name, section, key):
        """
        读取配置文件
        :param file_name: 配置文件名称
        :param section: 配置文件的section
        :param key: 配置文件中的key
        :return:
        """
        try:
            config = self.get_config_file(file_name)
            value = config.get(section, key)
            return value
        except Exception as e:
            print("Get value failed:" + str(e))


if __name__ == '__main__':
    MyConfig().get_value('url.conf', 'url', 'test_url')
